package concurrency_design_model

import (
	"fmt"
	"sync"
	"time"
)

// 我们可以通过close()关闭一个通道来实现广播的效果，所有从关闭通道接收的操作均会收到一个零值和一个可选的失败标志
func WorkerTest() {
	cancel := make(chan bool)
	var wg sync.WaitGroup
	for i := 0; i < 10; i++ {
		wg.Add(1)
		go worker(&wg, cancel)
	}
	time.Sleep(time.Second)
	close(cancel)
	wg.Wait()
}

func worker(wg *sync.WaitGroup, cannel chan bool) {
	defer wg.Done()
	for {
		select {
		default:
			fmt.Println("hello")
		case <-cannel:
			return
		}
	}
}
